#!/bin/sh

# Initialize the $iraf and environment.
if [ -z "$iraf" ]; then
  if [ -e "$HOME/.iraf/setup.sh" ]; then
    . "$HOME/.iraf/setup.sh"
  else
    . unix/hlib/setup.sh
  fi
else
    . "$iraf/unix/hlib/setup.sh"
fi


# Utility aliases.
. "$iraf/unix/hlib/util.sh"

if [ ! -n "$iraf" ]; then
    echo
    echo "Error:  You must have the iraf env variable defined !"
    echo
    exit 1
fi

exec=yes
arch=$("$iraf/unix/hlib/irafarch.sh" -actual)


#=============================================================================
# Process any command line arguments.
#=============================================================================
while [ -n "$1" ]; do
    case "$1" in
    "-n")                            # no execute
        exec=no
	;;
    *)
        ERRMSG "$0: unknown argument $1"
	;;
    esac

    if [ -n "$2" ]; then
        shift
    else
        break
    fi
done



#----------------------------------
# Determine platform architecture.
#----------------------------------

mach=$("$iraf/unix/hlib/irafarch.sh" -actual)
hmach=$("$iraf/unix/hlib/irafarch.sh" -actual)

echo "mach = $mach"
echo "hmach = $hmach"

make generic

echo "Making $arch binary distribution ...."
  make generic
  if [ "$exec" = "yes" ]; then
    tar czf "../${arch}-bin.tar.gz" "bin.$arch" "*/bin.$arch" "extern/*/bin.$arch"
  else
    echo "tar czf ../${arch}-bin.tar.gz bin.$arch */bin.$arch extern/*/bin.$arch"
  fi
echo "		Done"

exit 0
